package com.faxsun.web.security.authentication;

import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

public class ThirdPartyContext {
	private static final String FAIL = "redirect:/";

	private Map<String, ThirdPartyLoginAbs> sourceList;

	public Map<String, ThirdPartyLoginAbs> getSourceList() {
		return sourceList;
	}

	public void setSourceList(Map<String, ThirdPartyLoginAbs> sourceList) {
		this.sourceList = sourceList;
	}

	public String loginContext(String channel, String path, HttpServletRequest request, HttpServletResponse response) {
		if (sourceList.containsKey(channel)) {
			ThirdPartyLoginAbs abs = sourceList.get(channel);
			ThirdPartyObj obj3rd = abs.get3rdObj(request, response, channel, path);
			return abs.login(request.getSession(), obj3rd);
		} else {
			return FAIL;
		}
	}

	public void responseContext(String channel, HttpServletRequest request, HttpServletResponse response) {
		if (sourceList.containsKey(channel)) {
			ThirdPartyLoginAbs abs = sourceList.get(channel);
			abs.ResponseURL(request, response);
		}
	}

}
